// https://iai.sh.cn/problem/952
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL jisuan(LL a, LL b, int c) {
  LL ans = 1;
  while (b != 0) {
    if (b % 2 == 1)
      ans = (ans * a) % c;
    a = (a * a) % c;
    b = b >> 1;
  }
  return ans;
}

int main() {
  LL a, b, c;
  cin >> a >> b >> c;
  cout << jisuan(a, b, c);
  return 0;
}